﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<%@ Import Namespace="AgriMarketWebProj.AgriMarketService" %>
<%@ Import Namespace="AgriMarketWebProj.Models" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>

<asp:Content ID="Content2" ContentPlaceHolderID="TitleContent" runat="server">
    AgriMarket|Đấu giá
</asp:Content>


<asp:Content ID="ScriptContent" ContentPlaceHolderID="ScriptContent" runat="server">
    <script src="../../Scripts/AgriProj/Auction/AuctionView.js" type="text/javascript"></script>
    <script src="../../Scripts/AgriProj/Auction/Auction_AuctionIndex.js" type="text/javascript"></script>

    <link href="../../Content/Auction/AuctionView.css" rel="stylesheet" type="text/css" />
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="Content" runat="server">
    <% string tittleLink = ""; %>
	<div id="menu_vertical">
		<div id ="menurao" >
			<ul id="css3menu1" class="topmenu hormenu">
				<li class="topfirst"><a href="/Auction/ViewBuyAuctionIndex" class="horizontal_menu_a"><img src="../../Content/Images/bell.png" alt=""/>Đấu giá bán</a></li>
				<li class="topmenu"><a href="/Auction/ViewSellAuctionIndex" class="horizontal_menu_a"><img src="../../Content/Images/hammer2.png" alt=""/>Đấu giá mua</a></li>
				<li class="toplast"><a href="#" class="horizontal_menu_a"><img src="../../Content/Images/box-remove.png" alt=""/>Phân loại</a>
                    <ul>
                        <%if (ViewBag.TypeId == 1)
                          {
                              tittleLink = ViewBag.TypeView==1?"Danh sách đấu giá bán":"Danh sách đấu giá bán đang diễn ra"; %>
                        <li class="subfirst"><a href='/Auction/ViewBuyAuctionIndex'>Tất cả</a></li>
                        <li><a href='/Auction/BeingBuyAuctions'>Đang diễn ra</a></li>
                        <%}
                          else if (ViewBag.TypeId == 2)
                          {
                              tittleLink = ViewBag.TypeView == 1 ? "Danh sách đấu giá mua" : "Danh sách đấu giá mua đang diễn ra";  %>
                         <li><a href='/Auction/ViewSellAuctionIndex'>Tất cả</a></li>
                         <li><a href='/Auction/BeingSellAuctions'>Đang diễn ra</a></li>
                        <%}
                          else if (ViewBag.TypeId == 3)
                          {
                              tittleLink = ViewBag.TypeView == 1 ? "Danh sách đấu giá" : "Danh sách đấu giá đang diễn ra";  %>
                         <li><a href='/Auction/Index'>Tất cả</a></li>
                         <li><a href='/Auction/BeingAuctions'>Đang diễn ra</a></li>
                        <%} %>
	                </ul>
                </li>
                <% UserAccount currentUserAccount = ViewBag.CurrentUserAccount;%>
                <%if (currentUserAccount != null && currentUserAccount.TypeOfUser.TypeId != AdminCode.AdminTypeCode && ViewBag.TypeId!=3)
                  { %>
	                <li class="topmenu"><a href="#" class="horizontal_menu_a" onClick="slideToggleNewBuyAuctionDiv(); return false;"><img src="../../Content/Images/file.png" alt=""/>Đấu giá mới</a></li>
                <% }
                  else
                  {%>
                  <li class="topmenu"><a href="#" class="horizontal_menu_a" onClick="return false;"></a></li>
                <%} %>
			</ul>
		</div>
	</div>
    <div>
        <h2 style="text-align:center"><%=tittleLink %></h2>
    </div>
    <%  List<Auction> newUnfinishedAuctions = ViewBag.NewUnfinishedAuctions;
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        var serializedProducts = serializer.Serialize(ViewBag.AllProducts);
        Response.Write("<script type='text/javascript'>allProducts=" + serializedProducts + "</script>");%>
    <% if (currentUserAccount != null )
        { %>
        <div id='newBuyAuctionDiv'>
            <%
                ViewDataDictionary newViewData = new ViewDataDictionary();
                newViewData.Add("currentUserAccountName", currentUserAccount.UserName);
                newViewData.Add("TypeView", ViewBag.TypeView);
                if (ViewBag.TypeId == 1)
                {
                    if(currentUserAccount.TypeOfUser.TypeId != AdminCode.AdminTypeCode)
                        Html.RenderPartial("AddNewBuyAuctionView", (List<Product>)ViewBag.AllProducts, newViewData);
                    Response.Write("<script>autoLoadNextAuction(1," + ViewBag.TypeView + ");</script>");
                }
                else if (ViewBag.TypeId == 2)
                {
                    if (currentUserAccount.TypeOfUser.TypeId != AdminCode.AdminTypeCode)
                        Html.RenderPartial("AddNewSellAuctionView", (List<Product>)ViewBag.AllProducts, newViewData);
                    Response.Write("<script>autoLoadNextAuction(2," + ViewBag.TypeView + ");</script>");
                }
                else if (ViewBag.TypeId == 3) {
                    Response.Write("<script>autoLoadNextAuction(3," + ViewBag.TypeView + ");</script>");
                }
                %>
        </div>
    <%} %>
	<div id="data">
		<div id="auctionListDiv">
            <% 
                if (newUnfinishedAuctions != null && newUnfinishedAuctions.Count > 0)
                {
                    foreach (var auction in newUnfinishedAuctions)
                    {
                        Html.RenderAction("ViewAuction", new { auction = auction });
                    }
                }
            %>
        </div>   
	</div>
    <%
        if (newUnfinishedAuctions != null && newUnfinishedAuctions.Count > 0)
        {
            if (ViewBag.TypeId == 1)
            {
                Response.Write("<div class='BtnNNextAuctions' id='BtnNNextBuyAuctions'  onclick='loadNextBuyAuction(" + ViewBag.TypeView + "); ' >Read more</div>");
            }
            else if (ViewBag.TypeId == 2)
            {
                Response.Write("<div  class='BtnNNextAuctions' id='BtnNNextSellAuctions' value='Read more' onclick='loadNextSellAuction(" + ViewBag.TypeView + "); ' >Read more</div>");
            }
            else if (ViewBag.TypeId == 3)
            {
                Response.Write("<div  class='BtnNNextAuctions' id='BtnNNextAuctions' value='Read more' onclick='loadNextAuction(" + ViewBag.TypeView + "); ' >Read more</div>");
            }
            Response.Write("<input type='hidden' id='lastId' name='lastId' value='" + newUnfinishedAuctions[newUnfinishedAuctions.Count - 1].AuctionId.ToString() + "'  />");
        }
      %>
    <div id='dim'></div>
</asp:Content>
